
<?php
if(!isset($_SESSION)) session_start();
//if (isset($_REQUEST["section"])) $_SESSION["section"] = $_REQUEST["section"];
//if (isset($_REQUEST["area"])) $_SESSION["area"] = $_REQUEST["area"];

if (isset ($_FILES["file"])) {
    $area = $_SESSION["area"];
    $section =  $_SESSION["section"];
    
    $module = "{$_SERVER["DOCUMENT_ROOT"]}/media/{$area}/{$section}/";
    
    if (!is_dir($module)) mkdir($module, 0 , true);
    $target_path = "$module";
    
    $target_path = $target_path . basename( $_FILES["file"]['name']); 
    
    if(move_uploaded_file($_FILES["file{$i}"]['tmp_name'], $target_path)) {
                //echo "Image {$i} {$files[$i]} &rarr; {$_FILES["file{$i}"]["name"]}";
                echo "<script type=\"text/javascript\">";
                echo "parent.document.getElementById(\"mm_open\").click();";
                //echo "$(\"#mm_open\").click();";
                echo "</script>";
        
                //show_form ($i);
    } else{
                echo "<script type=\"text/javascript\">alert(\"There was an error uploading the file, please try again!\")</script>";
       
    }  
}

?>

<form enctype="multipart/form-data"  action="upload_media.php" method="POST">

<input name="file" type="file" />
    <input style="float:right" type="submit" value="Upload" />
</form>
